//充值提现记录tab切换
$('.account-tab a').click(function(){
    $('.account-tab a').removeClass('tab-active');
    $(this).addClass('tab-active');
})
$('.tab-bankcard').click(function(){
    $('.main-card').css('display','block');
    $('.wallet-not').css('display','none');
    $('.card-not').css('display','block');
    $('.ver-not').css('display','none');
})
$('.tab-wallet').click(function(){
    $('.main-card').css('display','none');
    $('.wallet-not').css('display','block');
    $('.card-not').css('display','none');
    $('.ver-not').css('display','block');
});
Handlebars.registerHelper('format', function (date,options) {

    var str = new Date(date).toLocaleString();
    var i = str.indexOf(' ');
    var str1 = str.substr(i + 1,2);
    var str2 = str.substr(i + 3,2);

    if (isNaN(str2)) {
        if (str1 == '上午') {
            str = str.replace(str.substr(i + 1,3),'0' + str.substr(i + 3,1));
        }else {
            str = str.replace(str.substr(i + 1,3),Number(str.substr(i + 3,1)) + 12);
        }
    }else{
        if (str1 == '上午') {
            str = str.replace(str.substr(i + 1,2),'');
        }else {
            if(Number(str2) == 12){
                str = str.replace(str.substr(i + 1,4),'00');
            }else {
                str = str.replace(str.substr(i + 1,4),Number(str.substr(i + 3,2)) + 12);
            }
        }
    }
    return str;
});
Handlebars.registerHelper('if_eq', function(v1, v2, opts) {
    if(v1 == v2)
    return opts.fn(this);
    else
    return opts.inverse(this);
});
        var tpl  =  $("#myTemplate").html();
        var template = Handlebars.compile(tpl);
        $.ajax({
           url:"/capital.json",
           type:"get",
            dataType:"json",
              data:{
                currentPage:1,
                walletType:1,
                pageSize:10,
                  type:1
              },
           success:function(res){
                // $.setAppData('totalPages',res.data.totalPages);
               var tpl1 = $("#myTemplate").html();
               $.ajax({
                   url:"/assets/script/pagination.hbs",
                   type:"get",
                   async:false,
                   success:function(data){
                       tpl1 = data;
                   },
                   error:function(err){

                   }
               });
               var template1 = Handlebars.compile(tpl1);
               $.ajax({
                   url:'capital.json',
                   type:'get',
                   dataType:'json',
                   data:{
                       currentPage:1,
                       walletType:1,
                       pageSize:10,
                       type:1
                   },
                   success:function(data){
                       var array=[];
                       for(var i=1;i<=data.data.totalPages;i++){
                           array.push(i);
                       }
                       data.array=array;
                       var html = template1(data);
                       $('.pagina').append(html);
                       $('.real a').click(function(){
                           $('.pages').css('display','block');
                       });
                       var total = data.data.totalPages;
                       $('.real a').data('total',total);
                       $(document).click(function(){
                           $('.pages').css('display','none');
                       });
                       $(".pages").click(function(event){
                           event.stopPropagation();
                       });
                       $('.real a').click(function(event){
                           event.stopPropagation();
                       });
                       //中间页数
                       $('.page a').click(function(){
                           $('.real a').html($(this).html());
                           $('.pages').css('display','none');
                           var current = $(this).data('p');
                           $('.real a').data('p',current);
                           $.ajax({
                               url:'capital.json',
                               type:'get',
                               data:{
                                   currentPage:current,
                                   walletType:1,
                                   pageSize:10,
                                   type:1
                               },
                               success:function(data){
                                   var html = template(data);
                                   $('.project-content').empty();
                                   $('.project-content').append(html);
                               },
                               error:function(msg){
                               }
                           })
                       });
                       //上一页
                       $('.prev').click(function(){
                           var current = Number($('.real a').data('p'))-1;
                           if(current<1){
                               current = 1;
                               $('.real a').data('p',current);
                               $('.real a').html('第'+current+'页');
                           }else{
                               $('.real a').data('p',current);
                               $('.real a').html('第'+current+'页');
                               $.ajax({
                                   url:'capital.json',
                                   type:'get',
                                   data:{
                                       currentPage:current,
                                       walletType:1,
                                       pageSize:10,
                                       type:1
                                   },
                                   success:function(data){
                                       var html = template(data);
                                       $('.project-content').empty();
                                       $('.project-content').append(html);
                                   },
                                   error:function(msg){
                                   }
                               })
                           }

                       });
                       //下一页
                       $('.next').click(function(){
                           var current = Number($('.real a').data('p'))+1;
                           var total = $('.real a').data('total');
                           if(current>total){
                               current = total;
                               $('.real a').data('p',current);
                               $('.real a').html('第'+current+'页');
                           }else{
                               $('.real a').data('p',current);
                               $('.real a').html('第'+current+'页');
                               $.ajax({
                                   url:'capital.json',
                                   type:'get',
                                   data:{
                                       currentPage:current,
                                       walletType:1,
                                       pageSize:10,
                                       type:1
                                   },
                                   success:function(data){
                                       var html = template(data);
                                       $('.project-content').empty();
                                       $('.project-content').append(html);
                                   },
                                   error:function(msg){
                                   }
                               })
                           }

                       });
                   },
                   error:function(){

                   }
               });
                var html = template(res);
                $('.main-con').empty();
                $('.main-con').append(html);
            },
            error: function(msg) {
                console.log(msg)
            }
        });
//过滤充值提现
$('.screening a').click(function(){
$('.screening a').removeClass('scr-active');
$(this).addClass('scr-active');
    var tpl  =  $("#myTemplate").html();
    var template = Handlebars.compile(tpl);
    var arr = [];
    arr.type = $(this).attr('data-p');
    $.ajax({
   url:"/capital.json",
   type:"get",
    dataType:"json",
      data:{
        walletType:1,
        currentPage:1,
        pageSize:10,
        type:arr.type
        },
   success:function(data){
       var tpl1 = $("#myTemplate").html();
       $.ajax({
           url:"/assets/script/pagination.hbs",
           type:"get",
           async:false,
           success:function(data){
               tpl1 = data;
           },
           error:function(err){

           }
       });
       var template1 = Handlebars.compile(tpl1);
       $.ajax({
           url:'capital.json',
           type:'get',
           dataType:'json',
           data:{
               currentPage:1,
               walletType:1,
               pageSize:10,
               type:arr.type
           },
           success:function(data){
               var array=[];
               for(var i=1;i<=data.data.totalPages;i++){
                   array.push(i);
               }
               data.array=array;
               var html = template1(data);
               $('.pagina').append(html);
               $('.real a').click(function(){
                   $('.pages').css('display','block');
               });
               var total = data.data.totalPages;
               $('.real a').data('total',total);
               $(document).click(function(){
                   $('.pages').css('display','none');
               });
               $(".pages").click(function(event){
                   event.stopPropagation();
               });
               $('.real a').click(function(event){
                   event.stopPropagation();
               });
               //中间页数
               $('.page a').click(function(){
                   $('.real a').html($(this).html());
                   $('.pages').css('display','none');
                   var current = $(this).data('p');
                   $('.real a').data('p',current);
                   $.ajax({
                       url:'capital.json',
                       type:'get',
                       data:{
                           currentPage:current,
                           walletType:1,
                           pageSize:10,
                           type:arr.type
                       },
                       success:function(data){
                           var html = template(data);
                           $('.project-content').empty();
                           $('.project-content').append(html);
                       },
                       error:function(msg){
                       }
                   })
               });
               //上一页
               $('.prev').click(function(){
                   var current = Number($('.real a').data('p'))-1;
                   if(current<1){
                       current = 1;
                       $('.real a').data('p',current);
                       $('.real a').html('第'+current+'页');
                   }else{
                       $('.real a').data('p',current);
                       $('.real a').html('第'+current+'页');
                       $.ajax({
                           url:'capital.json',
                           type:'get',
                           data:{
                               currentPage:current,
                               walletType:1,
                               pageSize:10,
                               type:arr.type
                           },
                           success:function(data){
                               var html = template(data);
                               $('.project-content').empty();
                               $('.project-content').append(html);
                           },
                           error:function(msg){
                           }
                       })
                   }

               });
               //下一页
               $('.next').click(function(){
                   var current = Number($('.real a').data('p'))+1;
                   var total = $('.real a').data('total');
                   if(current>total){
                       current = total;
                       $('.real a').data('p',current);
                       $('.real a').html('第'+current+'页');
                   }else{
                       $('.real a').data('p',current);
                       $('.real a').html('第'+current+'页');
                       $.ajax({
                           url:'capital.json',
                           type:'get',
                           data:{
                               currentPage:current,
                               walletType:1,
                               pageSize:10,
                               type:arr.type
                           },
                           success:function(data){
                               var html = template(data);
                               $('.project-content').empty();
                               $('.project-content').append(html);
                           },
                           error:function(msg){
                           }
                       })
                   }

               });
           },
           error:function(){

           }
       });
        var html = template(data);
        $('.main-con').empty();
        $('.main-con').append(html);
    },
    error: function(msg) {
        console.log(msg)
    }
})
})

////////
recharge();
$('.withdraw-rec').click(function(){
    withdraw();
});
$('.recharge-rec').click(function(){
    recharge();
});
function withdraw(){
    $('.recharge-thead').css('display','none');
    $('.withdraw-thead').css('display','table-header-group');
    $.ajax({
        url:"/assets/script/account-withdraw.hbs",
        type:"get",
        async:false,
        success:function(data){
            tpl2=data;
        }
    });
    var template2 = Handlebars.compile(tpl2);
    $.ajax({
        url:'/account-center.json',
        type: 'get',
        dataType:"json",
        success: function (data) {
            var html = template2(data);
            $('.history').empty();
            $('.history').append(html);
        },
        error:function (msg) {
            console.log(msg)
        }
    });
}
function recharge(){
    $('.recharge-thead').css('display','table-header-group');
    $('.withdraw-thead').css('display','none');
    $.ajax({
        url:"/assets/script/account-recharge.hbs",
        type:"get",
        async:false,
        success:function(data){
            tpl=data;
        }
    });
    var template = Handlebars.compile(tpl);
    $.ajax({
        url:'/account-center.json',
        type: 'get',
        dataType:"json",
        success: function (data) {
            // $('#pagination').jqPaginator({
            //     totalPages: data.data.totalPages,
            //     visiblePages: 10,
            //     currentPage: 1,
            //     onPageChange:function(currentPage,type){
            //         $.ajax({
            //             url:"/capital-detail.json",
            //             type:"get",
            //             dataType:"json",
            //             data:{
            //                 currentPage:currentPage,
            //                 pageSize:10,
            //                 walletType:$('.tab-active').attr('id')
            //             },
            //             success:function(data){
            //                 console.log(data)
            //                 var arr = [];
            //                 arr = data;
            //                 var html = template(data);
            //                 $('.main-con').empty();
            //                 $('.main-con').append(html);
            //             },
            //             error: function(msg) {
            //                 console.log(msg)
            //             }
            //         })
            //     },
            //     first: '<li class="first"><a href="javascript:void(0);">首页</a></li>',
            //     prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
            //     next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
            //     last: '<li class="last"><a href="javascript:void(0);">尾页</a></li>',
            //     page: '<li class="page"><a href="javascript:void(0);" class="page-a">{{page}}</a></li>',
            // });
            var html = template(data);
            $('.history').empty();
            $('.history').append(html);
        },
        error:function (msg) {
            console.log(msg)
        }
    });
}